<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let str1 = "12.3.1";
      let str2 = "12.7.8";
      let str3 = "1.5.6-alpha.1";
      let str4 = "7.1.6-beta";
      function* walk(str) {
        let part = "";
        let terminal = [".", "-"];
        for (let i = 0; i < str.length; i++) {
          if (terminal.includes(str[i])) {
            yield part;
            part = "";
          } else {
            part += str[i];
          }
        }
        if (part) {
          yield part;
        }
      }

      const iterator = walk(str3);
      for (const i of iterator) {
        console.log(i);
      }
    </script>
  </body>
</html>
